package dao;


import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import model.Course;
import util.ConnectionUtil;

public class CourseDao {
	
       public static ArrayList<Course> queryCourseList(){
    	   ArrayList<Course> courseList = new ArrayList<>();
    	   
    	   Connection conn = ConnectionUtil.getConnection();
    	   String sql = "SELECT * FROM course";
    	   try {
    		   Statement stat = conn.createStatement();
    		   ResultSet rs = stat.executeQuery(sql);
    		   
    		   while(rs.next()) {
    			   int courseid = rs.getInt(1);
    			   String coursename = rs.getString(2);
    			   
    			   Course course = new Course(courseid,coursename);
    			   courseList.add(course);
    		   }
    		   
    		   
    	   }catch(SQLException e) {
    		   e.printStackTrace();
    	   }
    	   
    	   return courseList;
       }
     
}
